<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>map/reduce</title>
	<!--<script src="https://cdn.jsdelivr.net/netnpm/vue/dist/vue.js"></script>-->
</head>
<body>
<script>
	//google:MapReduce:Simplified Date Processing on Large Clusters
	//Map
	function pow(x) {
		return x*x;
	}
	let arr = [1,2,3,4,5];
	let maps = arr.map(pow);
	console.log(maps);

	let arr1 = [1,3,5,7,9];
	var arr1Str = arr1.map(String);
	console.log(arr1Str);

	//Reduce
	let arr3 = [3,4,5];
	let arr3Result = arr3.reduce(function (x,y) {
		return x*y;
	});
	console.log(arr3Result);

	let arr4 = [1,3,4,6];
	var arr4Result = arr4.reduce(function (x,y) {
		return x*10 + y;
	})
	console.log(arr4Result);

	let str5 = "13479";
	let number6 = str5.split("")
		.map(x=>+x)
		.reduce((x,y) => x*10 + y);
	console.log(number6);
</script>
</body>
</html>